<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      v-model="form"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      :search.sync="query"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="menuRight">
        <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val, pageCode)"></user-table-config>
      </template>
      <template slot="menuLeft">
        <el-button type="warning" size="small" icon="el-icon-download" v-if="permission.iqcWaitIncomingList_export" @click="handleExport">导出</el-button>
      </template>
      <template slot-scope="{ row }" slot="menu">
        <el-button type="text" icon="el-icon-view" size="small" plain style="border: 0; background-color: transparent !important" @click.stop="handleView(row)">详情</el-button>
      </template>
    </avue-crud>
    <el-dialog append-to-body :close-on-click-modal="false" title="详情" :visible.sync="showDialog" v-if="showDialog" custom-class="iqcWaitIncomingList" width="80%" top="7vh">
      <avue-crud
        :page.sync="detail.page"
        :option="sheetOption"
        :data="detail.data"
        ref="addTableCrud"
        :key="timer"
        @current-change="detailCurrentChange"
        @size-change="detailSizeChange"
      >
      </avue-crud>
      <div slot="footer" class="avue-dialog__footer">
        <el-button size="small" icon="el-icon-circle-close" @click="showDialog = false">取消</el-button>
      </div>
    </el-dialog>
    <export-comp ref="exportComp" page-api-url="mes-warehouse/inbound-order/page" :option="option" :page="page" :query="exportParams" file-name="待入库单"> </export-comp>
  </basic-container>
</template>

<script>
import { getList, getDetail } from '@/api/quality/iqc-wait-incoming-list';
import { mapGetters } from 'vuex';
import userConfig from '@/mixins/userConfig';
import userTableConfig from '@/components/user-table-config';
import exportComp from '@/components/export-comp';
import { filterEmptyValues } from '@/util/util';

export default {
  components: {
    userTableConfig,
    exportComp
  },
  mixins: [userConfig()],
  data() {
    return {
      pageCode: 'IQC_WAIT_INCOMING_LIST',
      detailDialog: false,
      showDialog: false,
      form: {},
      model: {},
      query: {},
      loading: true,
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      exportParams: {},
      selectionList: [],
      tableOption: {},
      data: [],
      option: {
        height: 'calc(100vh - 300px)',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        border: true,
        index: true,
        indexLabel: '序号',
        addBtn: false,
        delBtn: false,
        editBtn: false,
        selection: true,
        viewBtn: false,
        dialogClickModal: false,
        labelWidth: 120,
        searchLabelWidth: 90,
        searchMenuSpan: 6,
        searchMenuPosition: 'right',
        menu: true,
        menuWidth: 200,
        columnBtn: false,
        column: [
          {
            label: '待入库单号',
            prop: 'inboundOrderNo',
            search: true,
            searchOrder: 1,
            searchSpan: 6
          },
          {
            label: '供应商编码',
            prop: 'vendorCode'
          },
          {
            label: '供应商名称',
            prop: 'vendorName',
            search: true,
            searchOrder: 2,
            searchSpan: 6
          },
          {
            label: '状态',
            prop: 'status',
            type: 'select',
            dataType: 'string',
            dicData: [
              { label: '正常', value: '1' },
              { label: '完成', value: '2' },
              { label: '取消', value: '3' },
              { label: '关闭', value: '4' }
            ],
            search: true,
            searchOrder: 3,
            searchSpan: 6,
            hide: true
          },
          {
            label: '数据来源',
            prop: 'sourceType',
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=sheet_source',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '备注',
            prop: 'remark',
            overHidden: true
          }
        ]
      },
      detail: {
        data: [],
        page: {
          pageSize: 20,
          currentPage: 1,
          total: 0
        }
      },
      sheetOption: {
        tip: false,
        searchShow: true,
        searchSpan: 4,
        searchMenuSpan: 6,
        dialogClickModal: false,
        height: '400',
        border: true,
        addBtn: false,
        editBtn: false,
        viewBtn: false,
        delBtn: false,
        columnBtn: false,
        cancelBtn: false,
        saveBtn: false,
        selection: false,
        menu: false,
        menuWidth: 100,
        page: true,
        index: true,
        indexLabel: '序号',
        refreshBtn: false,
        expandBtn: false,
        column: [
          {
            label: '待入库单号',
            prop: 'inboundOrderNo'
          },
          {
            label: '待入库单行号',
            prop: 'inboundOrderLot'
          },
          {
            label: '采购单号',
            prop: 'purchaseOrderNo'
          },
          {
            label: '采购单行号',
            prop: 'purchaseOrderLot'
          },
          {
            label: '物料编码',
            prop: 'partNo'
          },
          {
            label: '物料名称',
            prop: 'partName'
          },
          {
            label: '物料型号',
            prop: 'partModel'
          },
          {
            label: '物料规格',
            prop: 'partSpec'
          },
          {
            label: '物料品牌',
            prop: 'partBrand'
          },
          {
            label: '内部批次',
            prop: 'lotNo'
          },
          {
            label: '计划入库数',
            prop: 'planInboundQuantity'
          },
          {
            label: '已入库数量',
            prop: 'inboundQuantity'
          },
          {
            label: 'IQC检验单号',
            prop: 'iqcExamineNo'
          },
          {
            label: '状态',
            prop: 'status',
            type: 'select',
            dicData: [
              {
                label: '正常',
                value: 1
              },
              {
                label: '完成',
                value: 2
              },
              {
                label: '取消',
                value: 3
              },
              {
                label: '关闭',
                value: 4
              }
            ]
          }
        ]
      }
    };
  },
  computed: {
    ...mapGetters(['permission']),
    permissionList() {
      return {
        viewBtn: this.vaildData(this.permission.iqcWaitIncomingList_export, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(',');
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.$structuralSplit();
    });
  },
  methods: {
    handleView(row) {
      console.log(row, 'row');
      this.showDialog = true;
      getDetail(row.inboundOrderNo).then((res) => {
        let data = res.data.data;
        this.detail.data = data.records;
        this.detail.page.total = data.total;
      });
    },
    detailCurrentChange(currentPage) {
      this.detail.page.currentPage = currentPage;
    },
    detailSizeChange(pageSize) {
      this.detail.page.pageSize = pageSize;
    },
    beforeOpen(done, type) {
      if (['edit', 'view'].includes(type)) {
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },

    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query))
        .then((res) => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.selectionClear();
        })
        .finally(() => {
          this.loading = false;
        });
    },

    handleExport() {
      this.exportParams = Object.assign(filterEmptyValues(this.query));
      this.$refs.exportComp.visible = true;
    }
  }
};
</script>

<style scoped lang="scss">
$size: 16px;
.view-style {
  font-weight: bold;
  font-size: $size;
}
.iqc-placeholder {
  font-size: $size;
  color: #aaaaaa;
}

.iqcDialog {
  ::v-deep input[type='file'] {
    display: none !important;
  }
}
$BORDER-STYLE: 1px solid #f0f0f0 !important;
::v-deep .inspection-btn:hover {
  background-color: #dedede;
}
::v-deep .el-dialog__header {
  border-bottom: $BORDER-STYLE;
}

::v-deep .el-dialog__footer {
  border-top: $BORDER-STYLE;
}

.fill-screen-icon {
  color: #909399;
  font-size: 15px;
  float: right;
  padding-right: 25px;
  &:hover {
    color: #409eff;
  }
}

.group-title {
  border-bottom: 1px solid rgb(240, 240, 240) !important;
  font-size: 16px;
  font-weight: 500;
  height: 50px;
  line-height: 50px;
  color: rgba(0, 0, 0, 0.85);
  margin-bottom: 20px;
}
::v-deep .iqcWaitIncomingList {
  .el-dialog__body {
    padding: 20px;
  }
  .avue-crud__menu {
    display: none;
  }
  .common-modal-sub-title {
    display: flex;
    align-items: center;
    font-size: 16px;
    font-weight: bold;
    margin: 10px 0;
  }
}
</style>
